package com.bolt.support.spring.jpa.jpql;

import com.bolt.convention.data.Record;
import com.bolt.support.query.conditions.domain.SqlClause;

import javax.persistence.EntityManager;
import java.util.List;

public class JPAQuery<T> extends AbstractJPAQuery <T, JPAQuery <T>> {

    public JPAQuery(EntityManager em) {
        super(em);
    }

    @Override
    public  <T> JPAQuery <T> select(Class <T> type, SqlClause... clauses) {
        queryMetadata.setReturnClass(type);
        queryMetadata.addSelect(clauses);
        queryMetadata.setAllField(false);
        JPAQuery <T> newType = (JPAQuery <T>) this;
        return newType;
    }


    @Override
    public <T> JPAQuery<T> selectAll(Class<T> type, SqlClause... clauses) {
        queryMetadata.setReturnClass(type);
        queryMetadata.addSelect(clauses);
        queryMetadata.setAllField(true);
        JPAQuery <T> newType = (JPAQuery <T>) this;
        return newType;
    }

    @Override
    public <T> JPAQuery <T> selectDistinct(Class <T> type, SqlClause... clauses) {
        queryMetadata.setReturnClass(type);
        queryMetadata.addSelect(clauses);
        queryMetadata.setDistinct(true);
        queryMetadata.setAllField(false);
        JPAQuery <T> newType = (JPAQuery <T>) this;
        return newType;
    }

    @Override
    public  JPAQuery<Record> select(SqlClause... clauses) {
        return select(Record.class, clauses);
    }

    @Override
    public  JPAQuery<Record> selectDistinct(SqlClause... clauses) {
        return selectDistinct(Record.class, clauses);
    }

    @Override
    public List <T> fetch() {
        return super.fetch();
    }



}

 